package cate.game.role.res.guild.msg.basic;

import cate.common.annotation.OperationSetter;
import cate.common.table.d.GDOperation;
import cate.game.GameBody;
import cate.game.chat.ChatRequest;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdGuild;
import cate.game.role.Role;
import easy.java.dev.note.NoteField;

@ClientMsg(title = "创建公会的请求")
@OperationSetter(value = GDOperation.GUILD_CREATE)
public class CreateGuildReq implements MsgInput {
    @NoteField(value = "公会名")
    public String guildName;

    @NoteField(value = "公会旗帜图标")
    public int pattern;

    @NoteField(value = "公会旗帜背景")
    public int background;

    @NoteField(value = "公会名内容验证")
    public String checkSign;

    @NoteField(value = "公会公告")
    public String declaration;

    @NoteField(value = "验证设置")
    public boolean authentication;

    @NoteField(value = "等级要求")
    public int levelRequire;

    @NoteField(value = "战力要求")
    public long powerRequire;

    @Override
    public MsgConfig conf() {
        return MsgIdGuild.CREATE_GUILD_REQ;
    }

    @Override
    public void execute(GameBody game, ClientContext cc) {
        Role role = cc.getRole();
        if (!role.getRes().guild.checkGuild().ok()) {
            try {
                ChatRequest.checkSign(this.guildName, this.checkSign);
                game.res.guild.createGuild(role, guildName, pattern, background, declaration, authentication, levelRequire, powerRequire);
            } catch (Exception e) {
                game.notice.message(role, e.getMessage());
            }
        } else {
            game.notice.message(role, "您已加入过公会");
        }
    }
}
